home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / include / pbmplus / pbmplus.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-03  |  5.9 KB  |  197 lines

  1. /* pbmplus.h - header file for PBM, PGM, PPM, and PNM
  2. **
  3. ** Copyright (C) 1988, 1989, 1991 by Jef Poskanzer.
  4. **
  5. ** Permission to use, copy, modify, and distribute this software and its
  6. ** documentation for any purpose and without fee is hereby granted, provided
  7. ** that the above copyright notice appear in all copies and that both that
  8. ** copyright notice and this permission notice appear in supporting
  9. ** documentation.  This software is provided "as is" without express or
  10. ** implied warranty.
  11. */
  12.  
  13. #ifndef _PBMPLUS_H_
  14. #define _PBMPLUS_H_
  15.  
  16. #include <sys/types.h>
  17. #include <ctype.h>
  18. #include <stdio.h>
  19.  
  20. #if defined(USG) || defined(SVR4)
  21. #define SYSV
  22. #endif
  23. #if ! ( defined(BSD) || defined(SYSV) || defined(MSDOS) )
  24. /* CONFIGURE: If your system is >= 4.2BSD, set the BSD option; if you're a
  25. ** System V site, set the SYSV option; and if you're IBM-compatible, set
  26. ** MSDOS.  If your compiler is ANSI C, you're probably better off setting
  27. ** SYSV - all it affects is string handling.
  28. */
  29. #define BSD
  30. /* #define SYSV */
  31. /* #define MSDOS */
  32. #endif
  33.  
  34. /* CONFIGURE: If you want to enable writing "raw" files, set this option.
  35. ** "Raw" files are smaller, and much faster to read and write, but you
  36. ** must have a filesystem that allows all 256 ASCII characters to be read
  37. ** and written.  You will no longer be able to mail P?M files without 
  38. ** using uuencode or the equivalent, or running the files through pnmnoraw.
  39. ** Note that reading "raw" files works whether writing is enabled or not.
  40. */
  41. #define PBMPLUS_RAWBITS
  42.  
  43. /* CONFIGURE: PGM can store gray values as either bytes or shorts.  For most
  44. ** applications, bytes will be big enough, and the memory savings can be
  45. ** substantial.  However, if you need more than 8 bits of grayscale resolution,
  46. ** then define this symbol.
  47. */
  48. /* #define PGM_BIGGRAYS */
  49.  
  50. /* CONFIGURE: Normally, PPM handles a pixel as a struct of three grays.
  51. ** If grays are stored in bytes, that's 24 bits per color pixel; if
  52. ** grays are stored as shorts, that's 48 bits per color pixel.  PPM
  53. ** can also be configured to pack the three grays into a single longword,
  54. ** 10 bits each, 30 bits per pixel.
  55. **
  56. ** If you have configured PGM with the PGM_BIGGRAYS option, AND you don't
  57. ** need more than 10 bits for each color component, AND you care more about
  58. ** memory use than speed, then this option might be a win.  Under these
  59. ** circumstances it will make some of the programs use 1.5 times less space,
  60. ** but all of the programs will run about 1.4 times slower.
  61. **
  62. ** If you are not using PGM_BIGGRAYS, then this option is useless -- it
  63. ** doesn't save any space, but it still slows things down.
  64. */
  65. /* #define PPM_PACKCOLORS */
  66.  
  67. /* CONFIGURE: uncomment this to enable debugging checks. */
  68. /* #define DEBUG */
  69.  
  70. #ifndef _SCO_DS
  71. #ifdef SYSV
  72.  
  73. #include <string.h>
  74. #define index(s,c) strchr(s,c)
  75. #define rindex(s,c) strrchr(s,c)
  76. #define srandom(s) srand(s)
  77. #define random rand
  78. #define bzero(dst,len) memset(dst,0,len)
  79. #define bcopy(src,dst,len) memcpy(dst,src,len)
  80. #define bcmp memcmp
  81. extern void srand();
  82. extern int rand();
  83.  
  84. #else /*SYSV*/
  85.  
  86. #include <strings.h>
  87. extern void srandom();
  88. extern long random();
  89.  
  90. #endif /*SYSV*/
  91.  
  92. extern int atoi();
  93. extern void exit();
  94. extern long time();
  95. extern int write();
  96. #endif /* _SCO_DS */
  97.  
  98. /* CONFIGURE: On some systems, malloc.h doesn't declare these, so we have
  99. ** to do it.  On other systems, for example HP/UX, it declares them
  100. ** incompatibly.  And some systems, for example Dynix, don't have a
  101. ** malloc.h at all.  A sad situation.  If you have compilation problems
  102. ** that point here, feel free to tweak or remove these declarations.
  103. */
  104. #include <malloc.h>
  105. #ifndef _SCO_DS
  106. extern char* malloc();
  107. extern char* realloc();
  108. extern char* calloc();
  109. #endif /* _SCO_DS */
  110.  
  111. /* CONFIGURE: Some systems don't have vfprintf(), which we need for the
  112. ** error-reporting routines.  If you compile and get a link error about
  113. ** this routine, uncomment the first define, which gives you a vfprintf
  114. ** that uses the theoretically non-portable but fairly common routine
  115. ** _doprnt().  If you then get a link error about _doprnt, or
  116. ** message-printing doesn't look like it's working, try the second
  117. ** define instead.
  118. */
  119. /* #define NEED_VFPRINTF1 */
  120. /* #define NEED_VFPRINTF2 */
  121.  
  122. /* End of configurable definitions. */
  123.  
  124.  
  125. #undef max
  126. #define max(a,b) ((a) > (b) ? (a) : (b))
  127. #undef min
  128. #define min(a,b) ((a) < (b) ? (a) : (b))
  129. #undef abs
  130. #define abs(a) ((a) >= 0 ? (a) : -(a))
  131. #undef odd
  132. #define odd(n) ((n) & 1)
  133.  
  134.  
  135. /* Definitions to make PBMPLUS work with either ANSI C or C Classic. */
  136.  
  137. #if defined(__STDC__)
  138. #define ARGS(alist) alist
  139. #else /*__STDC__*/
  140. #define ARGS(alist) ()
  141. #define const
  142. #endif /*__STDC__*/
  143.  
  144.  
  145. /* Initialization. */
  146.  
  147. void pm_init ARGS(( int* argcP, char* argv[] ));
  148.  
  149.  
  150. /* Variable-sized arrays definitions. */
  151.  
  152. char** pm_allocarray ARGS(( int cols, int rows, int size ));
  153. char* pm_allocrow ARGS(( int cols, int size ));
  154. void pm_freearray ARGS(( char** its, int rows ));
  155. void pm_freerow ARGS(( char* itrow ));
  156.  
  157.  
  158. /* Case-insensitive keyword matcher. */
  159.  
  160. int pm_keymatch ARGS(( char* str, char* keyword, int minchars ));
  161.  
  162.  
  163. /* Log base two hacks. */
  164.  
  165. int pm_maxvaltobits ARGS(( int maxval ));
  166. int pm_bitstomaxval ARGS(( int bits ));
  167.  
  168.  
  169. /* Error handling definitions. */
  170.  
  171. void pm_message ARGS(( char*, ... ));
  172. void pm_error ARGS(( char*, ... ));            /* doesn't return */
  173. void pm_perror ARGS(( char* reason ));            /* doesn't return */
  174. void pm_usage ARGS(( char* usage ));            /* doesn't return */
  175.  
  176.  
  177. /* File open/close that handles "-" as stdin and checks errors. */
  178.  
  179. FILE* pm_openr ARGS(( char* name ));
  180. FILE* pm_openw ARGS(( char* name ));
  181. void pm_close ARGS(( FILE* f ));
  182.  
  183.  
  184. /* Endian I/O. */
  185.  
  186. int pm_readbigshort ARGS(( FILE* in, short* sP ));
  187. int pm_writebigshort ARGS(( FILE* out, short s ));
  188. int pm_readbiglong ARGS(( FILE* in, long* lP ));
  189. int pm_writebiglong ARGS(( FILE* out, long l ));
  190. int pm_readlittleshort ARGS(( FILE* in, short* sP ));
  191. int pm_writelittleshort ARGS(( FILE* out, short s ));
  192. int pm_readlittlelong ARGS(( FILE* in, long* lP ));
  193. int pm_writelittlelong ARGS(( FILE* out, long l ));
  194.  
  195.  
  196. #endif /*_PBMPLUS_H_*/
  197.